export const plat = uni.getStorageSync('plat');
/* 根据平台类型判断是否是微信支付 */
export const pay = (res, pay_type) => {
    if (plat === 'mp-weixin') {
        return new Promise((resolve, reject) => {
            uni.requestPayment({
                provider: 'wxpay',
                timeStamp: res.timeStamp,
                nonceStr: res.nonceStr,
                package: res.package,
                signType: res.signType,
                paySign: res.paySign,
                success: function (res) {
                    console.log('success:' + JSON.stringify(res));
                    this.$u.toast(this.$t('操作成功'))
                    setTimeout(() => {
                        resolve(res)
                    }, 2000)
                },
                fail: function (err) {
                    console.log('fail:' + JSON.stringify(err));
                    this.$u.toast(this.$t("取消支付"))
                    reject(err)
                }
            });
        })
    } else if (plat === 'app') {
        return new Promise((resolve, reject) => {
            uni.requestPayment({
                provider: pay_type,
                orderInfo: res, // 微信-支付宝订单数据
                success: (res) => {
                    console.log('success-score-order:' + JSON.stringify(res));
                    this.$u.toast(this.$t('操作成功'))
                    setTimeout(() => {
                        resolve(res)
                    }, 2000)
                },
                fail: (err) => {
                    console.log('fail:' + JSON.stringify(err));
                    this.$u.toast(this.$t("取消支付"))
                    reject(err)
                },
            });
        })
    }
}
